/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function newPersonalPlan() {
    var formpanel = new Ext.FormPanel({
        frame:true,
        items:[{
                xtype : 'textfield',
                fieldLabel: 'name',
                  name: 'name',
                  anchor:'95%'
               },{
                xtype : 'textarea',
                  fieldLabel: 'description',
                  anchor:'95%',
                  name: 'description'
               }],
        buttons: [
            {
                text: 'OK',
                handler: function(){
                    win.hide();
                    var planname = document.getElementsByName("name")[0].value;
                    var plandescription = document.getElementsByName("description")[0].value;
                    Ext.Ajax.request({
                        url:'space.do?action=newPersonalPlan&userid='+userid+"&name="+planname+"&description="+plandescription,
                        method:'post',
                        
                        success: function(response) {
                            //alert(response.result);
                            var responseArray = eval("("+ response.responseText + ")");
                            var planid = responseArray.planid;
                            window.location.href="PersonalPlan.jsp?planid="+planid+"&userid="+userid;
                        },
                        failure: function(form, action) {
                            Ext.Msg.alert('Error', 'Reason\uff1a' + action.result.errors.info);
                        }

                    });
                }
            },{
                text: 'Cancel',
                handler: function(){
                    win.hide();
                }
        }]
    });
      var win = new Ext.Window({
                width:300,
                height:200,
                plain:true,
                title:"New Personal Plan",
                draggable:false,
                items:formpanel
                //html:"<input type='button'>",
                //buttons:[{text:"OK",handler:function(){win.close();}},{text:"Cancel",handler:function(){win.close();}}]
                });
    //win.setPosition(destX,destY);
    win.show();
        

}


